﻿        var citystateAutoSet = false;

jQuery(function($)
{
        $("#venuee_Shortname").change(function(evnt)
        {
                jQuery.getJSON(siteRoot + '/Venue/UniqueShortnameJson.rails',
                    { id: $("#venue_VenueID").val(), name: $(this).val() },
                    function(data, textStatus)
                    {
                        $("#msgVShortName").text(data.status);
                    });
            });

        $('#venue_ZipCode').change(function(evnt)
        {
                $("#imgLoading").show();
                jQuery.getJSON(siteRoot + '/Venue/CountyFromZip.rails',
                    { zip: $("#venue_ZipCode").val() },
                    function(loc, textStatus)
                    {
                        var cty;
                        var state;
                        var cnty;
                        var empty = {};
                       if(loc == null || loc == empty)
                       {
                            cty = "";
                            state = "";
                            cnty = "0";
                        }
                       else
                       {
                            cty = loc.City;
                            state = "NJ";
                            cnty = loc.County;
                            citystateAutoSet = true;
                        }
                        $("#venCounties").val(cnty);
                        $("#venCounties option").attr("selected", "");
                        $("option[value=" + cnty + "]").attr("selected", "selected");
                        $("#venue_State").val(state);
                        $("#venue_City").val(cty);
                        $("#imgLoading").hide();
                    });

            })
            .blur(function() 
            {
                if ($('#venue_ZipCode').val() > "" && $("#venCounties").val() == 0)
                    $('#venue_ZipCode').change();
            });

            $("#venue_City").change(function() { citystateAutoSet = false; });

});
function SubmitVenue(evnt) 
{
    var $ = jQuery;
    if (!citystateAutoSet) {
        $.post(siteRoot + '/venue/SaveLocation.rails',
        { zip: $('#venue_ZipCode').val(), city: $('#venue_City').val(), county: $('#venCounties').val() },
        function(data, textStatus) 
        {
        	//            $.growl("Success", 'Zip Code Info saved');
        	$('#StatusBar').jnotifyAddMessage({
        		text: 'Zip Code Info saved',
        		permanent: false,
        		type: 'message'
        	});

        }, "json"
        );
    }

    if($('#frmVenue').valid())
    {
        $.post(siteRoot + '/venue/Save.rails', $("#frmVenue").serialize(),
            function(body, status)
            {
//                $.growl("Success", 'Venue Info saved');
            	$('#StatusBar').jnotifyAddMessage({
            		text: 'Venue Info saved',
            		permanent: false,
            		type: 'message'
            	});
            }, "json"
        );
    }
}